<?php
header('Access-Control-Allow-Origin:*');
require dirname(__FILE__) . './Classes/PHPExcel.php';
if($_POST['title'] =="data"){
    $sation_device=json_decode($_POST['sation']);
    $other_device=json_decode($_POST['other']);
    $assited=json_decode($_POST['assisted']);
//     $sation_device=json_encode($_POST['sation'],JSON_UNESCAPED_UNICODE);
//     $other_device=json_encode($_POST['other'],JSON_UNESCAPED_UNICODE);
//     $assited=json_encode($_POST['assisted'],JSON_UNESCAPED_UNICODE);
    $sation_length = count($sation_device);
    $other_length = count($other_device);
    $assisted_length = count($assisted);

    $objPHPExcel = new PHPExcel();
    $objPHPExcel->getProperties()->setCreator("Made by Chromie Wang")
    ->setLastModifiedBy("sation")
    ->setTitle("case")
    ->setSubject("sation case")
    ->setDescription("sation case")
    ->setKeywords("sation case")
    ->setCategory("sation case");  
    
    $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(12);
    $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(12);
    $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(12);
    $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(12);
    $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(12);
    $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(12);
    $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(12);


    $objPHPExcel->getActiveSheet()->mergeCells('A1:G1');
    $objPHPExcel->getActiveSheet()->mergeCells('A2:G2');
    $objPHPExcel->getActiveSheet()->mergeCells('A10:G10');
    $objPHPExcel->getActiveSheet()->mergeCells('A11:G11');
    $objPHPExcel->getActiveSheet()->mergeCells('A16:G16');
    $objPHPExcel->getActiveSheet()->mergeCells('A17:G17');
    $objPHPExcel->getActiveSheet()->mergeCells('A20:G20');
    $objPHPExcel->getActiveSheet()->mergeCells('A22:B22');
    $objPHPExcel->getActiveSheet()->mergeCells('C22:D22');
    $objPHPExcel->getActiveSheet()->mergeCells('E22:F22');


    $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', '世迅项目设备清单和报价表')
            ->setCellValue('A2', '一、世讯设备')
            ->setCellValue('A3', '设备名称')
            ->setCellValue('B3', '型号')
            ->setCellValue('C3', '品牌')
            ->setCellValue('D3', '单位')
            ->setCellValue('E3', '单价')
            ->setCellValue('F3', '数量')
            ->setCellValue('G3', '总价');
            
    //  for($i=0;$i<count($sation_device);$i++){
    //     $objPHPExcel->setActiveSheetIndex(0)
    //     ->setCellValue('A'.($i+4), $sation_device[$i]->name)
    //     ->setCellValue('B'.($i+4), $sation_device[$i]->product_model)
    //     ->setCellValue('C'.($i+4), $sation_device[$i]->brand)
    //     ->setCellValue('D'.($i+4), $sation_device[$i]->unit)
    //     ->setCellValue('E'.($i+4), $sation_device[$i]->unit_price)
    //     ->setCellValue('F'.($i+4), $sation_device[$i]->num)
    //     ->setCellValue('G'.($i+4), $sation_device[$i]->total)
    // }
    // $objPHPExcel->setCellValue('A'.(4+$sation_length), '小计：1470元');




//     $objPHPExcel->setActiveSheetIndex(0)
//             ->setCellValue('A4', '总线电源')
//             ->setCellValue('A5', 'APP网关')
//             ->setCellValue('A6', '红外学习器')
//             ->setCellValue('A7', '8键智能面板')
//             ->setCellValue('A8', '3路600W调光执行器')
//             ->setCellValue('A9', '12路16A开关执行器')
//             ->setCellValue('B4', 'SBP2002.6440')
//             ->setCellValue('B5', 'LAN2300.0201')
//             ->setCellValue('B6', 'SDT3005.0101')
//             ->setCellValue('B7', 'MPA1308.8612')
//             ->setCellValue('B8', 'SDM0106.2000')
//             ->setCellValue('B9', 'SDO0004.1611')
//             ->setCellValue('C4', 'SATION')
//             ->setCellValue('C5', 'SATION')
//             ->setCellValue('C6', 'SATION')
//             ->setCellValue('C7', 'SATION')
//             ->setCellValue('C8', 'SATION')
//             ->setCellValue('C9', 'SATION')
//             ->setCellValue('D4', '台')
//             ->setCellValue('D5', '台')
//             ->setCellValue('D6', '台')
//             ->setCellValue('D7', '台')
//             ->setCellValue('D8', '台')
//             ->setCellValue('D9', '台')
//             ->setCellValue('E4', '10')
//             ->setCellValue('E5', '20')
//             ->setCellValue('E6', '200')
//             ->setCellValue('E7', '1000')
//             ->setCellValue('E8', '150')
//             ->setCellValue('E9', '90')
//             ->setCellValue('F4', '1')
//             ->setCellValue('F5', '1')
//             ->setCellValue('F6', '1')
//             ->setCellValue('F7', '1')
//             ->setCellValue('F8', '1')
//             ->setCellValue('F9', '1')
//             ->setCellValue('G4', '10')
//             ->setCellValue('G5', '20')
//             ->setCellValue('G6', '200')
//             ->setCellValue('G7', '1000')
//             ->setCellValue('G8', '150')
//             ->setCellValue('G9', '90')
//             ->setCellValue('A10', '小计：1470元');

//             $objPHPExcel->setActiveSheetIndex(0)
//             ->setCellValue('A11', '二、第三方设备')
//             ->setCellValue('A12', '设备名称')
//             ->setCellValue('B12', '型号')
//             ->setCellValue('C12', '品牌')
//             ->setCellValue('D12', '单位')
//             ->setCellValue('E12', '单价')
//             ->setCellValue('F12', '数量')
//             ->setCellValue('G12', '总价');
            
//             $objPHPExcel->setActiveSheetIndex(0)
//             ->setCellValue('A13', '背景音乐-4分区')
//             ->setCellValue('A14', '窗帘电机+4米导轨')
//             ->setCellValue('A15', '魔镜')
//             ->setCellValue('B13', 'A75-4')
//             ->setCellValue('B14', 'DT300')
//             ->setCellValue('B15', 'M1')
//             ->setCellValue('C13', '泊声')
//             ->setCellValue('C14', '杜亚')
//             ->setCellValue('C15', '锐吉')
//             ->setCellValue('D13', '套')
//             ->setCellValue('D14', '台')
//             ->setCellValue('D15', '套')
//             ->setCellValue('E13', '45')
//             ->setCellValue('E14', '78')
//             ->setCellValue('E15', '522')
//             ->setCellValue('F13', '1')
//             ->setCellValue('F14', '1')
//             ->setCellValue('F15', '1')
//             ->setCellValue('G13', '45')
//             ->setCellValue('G14', '78')
//             ->setCellValue('G15', '522')
//             ->setCellValue('A16', '小计：645元');

//             $objPHPExcel->setActiveSheetIndex(0)
//             ->setCellValue('A17', '三、辅材')
//             ->setCellValue('A18', '设备名称')
//             ->setCellValue('B18', '型号')
//             ->setCellValue('C18', '品牌')
//             ->setCellValue('D18', '单位')
//             ->setCellValue('E18', '单价')
//             ->setCellValue('F18', '数量')
//             ->setCellValue('G18', '总价');

//             $objPHPExcel->setActiveSheetIndex(0)
//             ->setCellValue('A19', 'KNX总线')
//             ->setCellValue('B19', 'J-Y(ST)YH-2*2*0.8')
//             ->setCellValue('C19', 'VOKA')
//             ->setCellValue('D19', '米')
//             ->setCellValue('E19', '2.5')
//             ->setCellValue('F19', '500')
//             ->setCellValue('G19', '1250')
//             ->setCellValue('A20', '小计：1250元')
//             ->setCellValue('A22', '总计：3365元')
//             ->setCellValue('C22', '折扣：10%')
//             ->setCellValue('E22', '折后报价：3028.5元');


    


    $objPHPExcel->getActiveSheet()->setTitle('经济版');
    $objPHPExcel->setActiveSheetIndex(0);

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $objWriter->save('./export2/'.'sation'.date('Ymd-His').'.xlsx');

}
?>